package com.lhkj.ct.admin.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.Option;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.base.validator.group.ValGroups;
import com.lhkj.ct.meta.admin.model.entity.TblPost;
import com.lhkj.ct.meta.admin.service.SysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 *      岗位接口
 * </p>
 */
@RestController
@RequestMapping("api/system/post")
@ApiSupport(order = 7)
@Api(tags = {"07.岗位接口"})
@Validated
public class SysPostController {

    @Resource
    private SysPostService sysPostService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "岗位分页列表", notes = "岗位分页查询")
    @GetMapping("list")
    ////@RequiresPermissions(value = "system:post:list")
    public ActionResult<IPage<TblPost>> list(TblPost employee, PageQuery pageQuery) {
        return ActionResult.success(sysPostService.selectPostPage(employee, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取岗位下拉选项")
    @GetMapping("{organId}/options")
    public ActionResult<List<Option<String>>> listDeptOptions(@PathVariable String organId) {
        return ActionResult.success(sysPostService.listOptions(organId));
    }


    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "岗位表单数据", notes = "查看岗位信息")
    @GetMapping("get/{id}")
    ////@RequiresPermissions(value = {"system:employee:edit", "system:employee:get"}, logical = Logical.OR)
    public ActionResult<?> get(@PathVariable String id) {
        TblPost target = sysPostService.getById(id);
        if (target == null) {
            return ActionResult.fail("菜单不存在或已删除！");
        }
        return ActionResult.success(target);
    }

    @ApiOperationSupport(order = 3)
    @PostMapping("insert")
    @ApiOperation(value = "新增", notes = "新增岗位")
    @Log(title = "岗位管理", actionType = ActionType.INSERT)
    ////@RequiresPermissions(value = "system:employee:insert")
    public ActionResult<Void> insert(@Validated(ValGroups.Insert.class) @RequestBody TblPost entity) {
        return ActionResult.judge(sysPostService.insert(entity));
    }

    @ApiOperationSupport(order = 4)
    @PutMapping("update")
    @ApiOperation(value = "编辑", notes = "编辑岗位")
    @Log(title = "岗位管理", actionType = ActionType.UPDATE)
    ////@RequiresPermissions(value = "system:employee:edit")
    public ActionResult<Void> update(@Validated(ValGroups.Update.class) @RequestBody TblPost entity) {
        return ActionResult.judge(sysPostService.updateById(entity));
    }

    @ApiOperationSupport(order = 5)
    @DeleteMapping("delete")
    @ApiOperation(value = "删除", notes = "删除岗位")
    @Log(title = "岗位管理", actionType = ActionType.DELETE)
    ////@RequiresPermissions(value = "system:employee:delete")
    public ActionResult<Void> delete(@Validated @RequestBody @NotEmpty(message = "id不能为空") List<String> ids) {
        return ActionResult.judge(sysPostService.removeByIds(ids));
    }
}
